package com.azhon.basic.view;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.azhon.basic.R;
import com.azhon.basic.utils.DensityUtil;
import com.github.ybq.android.spinkit.style.DoubleBounce;

import static com.azhon.basic.view.Colors.colors;

/**
 * 项目名:    TODO-MVVM
 * 包名       com.azhon.basic.view
 * 文件名:    LoadingDialog
 * 创建时间:  2019-03-29 on 11:30
 * 描述:     TODO 等待对话框
 *
 * @author 阿钟
 */

public class LoadingDialog extends Dialog {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.LoadingDialog);
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.dialog_loading);
        DoubleBounce doubleBounce = new DoubleBounce();
        doubleBounce.setBounds(0, 0, 100, 100);
        doubleBounce.setColor(colors[8]);
        ProgressBar progressbar = findViewById(R.id.progressbar);
        progressbar.setIndeterminateDrawable(doubleBounce);
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = DensityUtil.dip2px(context, 120);
        lp.height = DensityUtil.dip2px(context, 120);
        lp.gravity = Gravity.CENTER;
        window.setAttributes(lp);
    }

    /**
     * 设置等待提示信息
     */
    public void setLoadingMsg(String msg) {
        if (TextUtils.isEmpty(msg)) {
            return;
        }
        TextView tvMsg = findViewById(R.id.tv_msg);
        tvMsg.setText(msg);
    }
}
